package com.cmcc.groupcontacts.numbersearch.dao;

import java.util.ArrayList;

import com.cmcc.groupcontacts.base.BaseDAO;
import com.cmcc.groupcontacts.base.BaseModel;
import com.cmcc.groupcontacts.numbersearch.model.SearchNumber;

public class SearchNumberDao extends BaseDAO<SearchNumber> {
	public static String TABLE_NAME = "searchnumber";
	public SearchNumberDao() {
		super(TABLE_NAME);
	}

	@Override
	protected SearchNumber getInstance() {
		return new SearchNumber();
	}

	@Override
	protected String[] getBeanAllCols() {
		return SearchNumber.MetaData.ALL_COLS;
	}

	@Override
	protected void afterGetColValue(BaseModel bean, String colName, String value) {
		super.afterGetColValue(bean, colName, value);
		SearchNumber item = (SearchNumber) bean;
		if (SearchNumber.MetaData.id.equals(colName))
			item.id = Integer.valueOf(value);
		else if (SearchNumber.MetaData.name.equals(colName))
			item.name = value;
		else if (SearchNumber.MetaData.number.equals(colName))
			item.number = value;
		else if (SearchNumber.MetaData.address.equals(colName))
			item.address = value;
		else if (SearchNumber.MetaData.locationX.equals(colName))
			item.locationX = value;
		else if (SearchNumber.MetaData.locationY.equals(colName))
			item.locationY = value;
		else if (SearchNumber.MetaData.categoryId.equals(colName))
			item.categoryId = Integer.valueOf(value);
	}
	
	public ArrayList<SearchNumber> loadByKey(String key){
		return query("select * from searchnumber where name like '%"+key+"%' or number like '%"+key+"%'" );
	}
	
	public ArrayList<SearchNumber> loadByCategory(int categoryId){
		return query("select * from searchnumber where category_id="+categoryId);
	}
}
